//
//  StandardAnswerTableViewCell.m
//  SafeFoodManagerDemo
//
//  Created by ios-1 on 2018/3/8.
//  Copyright © 2018年 bob. All rights reserved.
//

#import "StandardAnswerTableViewCell.h"

@implementation StandardAnswerTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)refreshData:(QuestionDetailModel*)detailModel;
{
    NSString * suggest = detailModel.data.suggest.length>0?detailModel.data.suggest:@"暂无";
    NSString *text = [NSString stringWithFormat:@"标准答案：\n%@\n标准建议：\n%@",detailModel.data.answer,suggest];
    
    //设置文本属性
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc]init];
    //设置行间距
    [paraStyle setLineSpacing:5];
    [paraStyle setLineBreakMode:NSLineBreakByWordWrapping];
    //字体大小
    UIFont *textFont = [UIFont systemFontOfSize:14];
    //字体颜色
    UIColor *textColor = [UIColor lightGrayColor];
    NSDictionary *textDic = @{NSFontAttributeName : textFont,NSForegroundColorAttributeName : textColor,NSParagraphStyleAttributeName : paraStyle};
    //富文本
    NSAttributedString *attrText = [[NSAttributedString alloc]initWithString:text attributes:textDic];
    //计算文本的size
    CGSize textSize = [text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-50 , MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:textDic context:nil].size;
    self.contentLab.attributedText = attrText;
    
    //设置虚线边框
    CAShapeLayer *borderLayer = [CAShapeLayer layer];
    borderLayer.bounds = CGRectMake(0, 0, textSize.width + 10, textSize.height + 10);
    //中心点位置
    borderLayer.position = CGPointMake(textSize.width *0.5, textSize.height *0.5);
    
    borderLayer.path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, kScreenWidth-50 , textSize.height + 10)].CGPath;
    //边框的宽度
    borderLayer.lineWidth = 2;
    //边框虚线线段的宽度
    borderLayer.lineDashPattern = @[@5,@5];
    borderLayer.fillColor = [UIColor clearColor].CGColor;
    borderLayer.strokeColor = TBColorProvideBtnbg.CGColor;
    [self.contentLab.layer addSublayer:borderLayer];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
